
#include "optionsWindow.h"

#include <QtGui/QCheckBox>

/*----------------------------------------------------------------------------*/


OptionsWindow::OptionsWindow()
	:	m_ui( new Ui::OptionsUi )
	,	m_linesFramesShowed( Qt::Checked )
	,	m_wordsFramesShowed( Qt::Checked )
	,	m_symbsFramesShowed( Qt::Checked )
	,	m_imageSizeValue( 0 )
	,	m_imageContrValue( 0 )
	,	m_lineExpandFactor( 0.0 )
	,	m_lineTopFactor( 0.0 )
	,	m_lineBotFactor( 0.0 )
	,	m_wordLeftFactor( 0.0 )
	,	m_wordRightFactor( 0.0 )
	,	m_symbIntervalFactor( 0.0 )
	,	m_symbBrightFactor( 0.0 )
	,	m_symbWidthFactor( 0.0 )
{
	m_ui->setupUi( this );

	/** OK button */
	connect( m_ui->m_okButton, SIGNAL( clicked() ), this, SLOT( SaveChages() ) );

	/** Cancel button */
	connect( m_ui->m_cancelButton, SIGNAL( clicked() ), this, SLOT( DiscardChanges() ) );

	/** init options from gui */
	StoreOptionsFromGui();
}

/*----------------------------------------------------------------------------*/


OptionsWindow::~OptionsWindow()
{
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::ShowCentered( QWidget& _parent )
{
	/** move child window to the parent's center */
	this->move( _parent.frameGeometry().center() - this->rect().center() );
	this->show();
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::SaveChages()
{
	StoreOptionsFromGui();
	this->hide();
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::DiscardChanges()
{
	/** frames display options */
	m_ui->m_showLinesFrames->setCheckState( m_linesFramesShowed );
	m_ui->m_showWordsFrames->setCheckState( m_wordsFramesShowed );
	m_ui->m_showSymbsFrames->setCheckState( m_symbsFramesShowed );	

	/** image parameters */
	m_ui->m_imageSizeSpinBox->setValue( m_imageSizeValue );
	m_ui->m_imageContrSpinBox->setValue( m_imageContrValue );

	/** image parameters */
	m_ui->m_lineExpandFactor->setValue( m_lineExpandFactor );
	m_ui->m_lineTopFactor->setValue( m_lineTopFactor );
	m_ui->m_lineBotFactor->setValue( m_lineBotFactor );

	/** word parameters */
	m_ui->m_wordLeftFactor->setValue( m_wordLeftFactor );
	m_ui->m_wordRightFactor->setValue( m_wordRightFactor );

	/** symbol parameters */
	m_ui->m_symbIntervalFactor->setValue( m_symbIntervalFactor );
	m_ui->m_symbBrightFactor->setValue( m_symbBrightFactor );
	m_ui->m_symbWidthFactor->setValue( m_symbWidthFactor );

	this->hide();
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::StoreOptionsFromGui()
{
	/** frames display options */
	m_linesFramesShowed = m_ui->m_showLinesFrames->checkState();
	m_wordsFramesShowed = m_ui->m_showWordsFrames->checkState();
	m_symbsFramesShowed = m_ui->m_showSymbsFrames->checkState();

	/** image parameters */
	m_imageSizeValue  = m_ui->m_imageSizeSpinBox->value();
	m_imageContrValue = m_ui->m_imageContrSpinBox->value();	

	/** line parameters */
	m_lineExpandFactor = m_ui->m_lineExpandFactor->value();
	m_lineTopFactor = m_ui->m_lineTopFactor->value();
	m_lineBotFactor = m_ui->m_lineBotFactor->value();

	/** word parameters */
	m_wordLeftFactor  = m_ui->m_wordLeftFactor->value();
	m_wordRightFactor = m_ui->m_wordRightFactor->value();

	/** symbol parameters */
	m_symbIntervalFactor = m_ui->m_symbIntervalFactor->value();
	m_symbBrightFactor   = m_ui->m_symbBrightFactor->value();
	m_symbWidthFactor    = m_ui->m_symbWidthFactor->value();

	/** emit signal */
	EmitFramesShowState();
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::closeEvent( QCloseEvent* _event )
{
	DiscardChanges();
	_event->accept();
}


/*----------------------------------------------------------------------------*/


int OptionsWindow::GetImageSizeValue()
{
	return m_imageSizeValue;
}


/*----------------------------------------------------------------------------*/


int OptionsWindow::GetImageContrastValue()
{
	return m_imageContrValue;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetLineExpandFactor()
{
	return m_lineExpandFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetLineTopFactor()
{
	return m_lineTopFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetLineBotFactor()
{
	return m_lineBotFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetWordLeftFactor()
{
	return m_wordLeftFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetWordRightFactor()
{
	return m_wordRightFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetSymbIntervalFactor()
{
	return m_symbIntervalFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetSymbBrightFactor()
{
	return m_symbBrightFactor;
}


/*----------------------------------------------------------------------------*/


float OptionsWindow::GetSymbWidthFactor()
{
	return m_symbWidthFactor;
}


/*----------------------------------------------------------------------------*/


void OptionsWindow::EmitFramesShowState()
{
	/** emit signal */
	emit FramesShowState(	(bool)m_linesFramesShowed,
							(bool)m_wordsFramesShowed,
							(bool)m_symbsFramesShowed	);
}


/*----------------------------------------------------------------------------*/

